<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="学年" prop="schoolYear">
        <el-select
          v-model="queryParams.schoolYear"
          placeholder="请选择学年"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in this.getDictDatas('school_year')"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="学期" prop="semester">
        <el-select
          v-model="queryParams.semester"
          placeholder="请选择学期"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in this.getDictDatas('college_semester_status')"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          @click="handleAdd"
          v-hasPermi="['collegebase:reward-punish-record:create']"
          >新增</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          @click="handleExport"
          :loading="exportLoading"
          v-hasPermi="['collegebase:reward-punish-record:export']"
          >导出</el-button
        >
      </el-col>-->
      <el-col :span="1.5">
        <el-button type="primary" plain @click="handleRewardpunish"
          >奖惩功能</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
        :columns="columns"
      ></right-toolbar>
    </el-row>

    <!-- 列表 -->
    <el-table v-loading="loading" :data="list">
      <el-table-column
        label="编号"
        v-if="columns[0].visible"
        align="center"
        prop="serialNumber"
        show-overflow-tooltip
      />
      <el-table-column
        label="学院"
        v-if="columns[1].visible"
        align="center"
        prop="collegeName"
        show-overflow-tooltip
      />
      <el-table-column
        label="班级"
        v-if="columns[2].visible"
        align="center"
        prop="classesName"
        show-overflow-tooltip
      />
      <el-table-column
        label="学年"
        v-if="columns[3].visible"
        align="center"
        prop="schoolYear"
        key="3"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <dict-tag
            :type="DICT_TYPE.SCHOOL_YEAR"
            :value="scope.row.schoolYear"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="学期"
        v-if="columns[4].visible"
        align="center"
        prop="semester"
        key="4"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <dict-tag
            :type="DICT_TYPE.COLLEGE_SEMESTER_STATUS"
            :value="scope.row.semester"
          />
        </template>
      </el-table-column>
      <!--      <el-table-column label="班级"  align="center" prop="classesName" />-->
      <el-table-column
        label="学号"
        v-if="columns[5].visible"
        align="center"
        prop="studentNumber"
        show-overflow-tooltip
      />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="165px"
        v-if="columns[6].visible"
        key="6"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['collegebase:reward-punish-record:update']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['collegebase:reward-punish-record:delete']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加修改组件 -->
    <form-edit
      :show.sync="open"
      :title="title"
      @success="getList"
      ref="editDialog"
    ></form-edit>
    <reward-punish :show.sync="rewardpunishFlag"></reward-punish>
  </div>
</template>

<script>
import {
  createRewardPunishRecord,
  updateRewardPunishRecord,
  deleteRewardPunishRecord,
  getRewardPunishRecord,
  getRewardPunishRecordPage,
  exportRewardPunishRecordExcel,
} from "@/api/collegebase/rewardPunishRecord";
import formEdit from "./formEdit";
import rewardPunish from "./rewardPunish.vue";
export default {
  name: "RewardPunishRecord",
  components: {
    formEdit,
    rewardPunish,
  },
  data() {
    return {
      columns: [
        { key: 0, label: `编号`, visible: true },
        { key: 1, label: `学院`, visible: true },
        { key: 2, label: `班级`, visible: true },
        { key: 3, label: `学年`, visible: true },
        { key: 4, label: `学期`, visible: true },
        { key: 5, label: `学号`, visible: true },
        { key: 6, label: `创建时间`, visible: false },
      ],
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 奖罚管理列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        schoolYear: null,
        semester: null,
      },
      rewardpunishFlag: false,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 执行查询
      getRewardPunishRecordPage(this.queryParams).then((response) => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.open = true;
      this.title = "添加奖罚管理";
      this.$refs.editDialog.initData({});
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const id = row.id;
      getRewardPunishRecord(id).then((response) => {
        let form = response.data;
        this.open = true;
        this.title = "修改奖罚管理";
        this.$refs.editDialog.initData(form);
      });
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id;
      this.$modal
        .confirm('是否确认删除奖罚管理编号为"' + row.serialNumber + '"的数据项?')
        .then(function () {
          return deleteRewardPunishRecord(id);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      let params = { ...this.queryParams };
      params.pageNo = undefined;
      params.pageSize = undefined;
      this.$modal
        .confirm("是否确认导出所有奖罚管理数据项?")
        .then(() => {
          this.exportLoading = true;
          return exportRewardPunishRecordExcel(params);
        })
        .then((response) => {
          this.$download.excel(response, "奖罚管理.xls");
          this.exportLoading = false;
        })
        .catch(() => { });
    },
    handleRewardpunish() {
      this.rewardpunishFlag = true;
    },
  },
};
</script>
